import 'package:flutter/material.dart';
import 'package:provide/provide.dart';
import '../../provide/count.dart';

/// 状态管理测试页面
class FlutterProvide extends StatefulWidget {
  @override
  _FlutterProvideState createState() => _FlutterProvideState();
}

class _FlutterProvideState extends State<FlutterProvide> {
  @override
  Widget build(BuildContext context) {
    return Scaffold(
      body: Center(
        child: Column(
          children: <Widget>[
            Number(),
            MyButton(),
          ],
        ),
      )
    );
  }
}

class Number extends StatefulWidget {
  @override
  _NumberState createState() => _NumberState();
}

class _NumberState extends State<Number> {
  @override
  Widget build(BuildContext context) {
    return Container(
      margin: EdgeInsets.only(top: 200),
      child: Provide<Counter>(
        builder: (context, child, counter){
          return Text('${counter.value}', style: Theme.of(context).textTheme.display1);
        }
      )
    );
  }
}

class MyButton extends StatefulWidget {
  @override
  _MyButtonState createState() => _MyButtonState();
}

class _MyButtonState extends State<MyButton> {
  @override
  Widget build(BuildContext context) {
    return Container(
      margin: EdgeInsets.only(top: 100),
      child: RaisedButton(
        onPressed: (){
          Provide.value<Counter>(context).incrementAdd();
        },
          onLongPress: (){
          Provide.value<Counter>(context).incrementSub();
          },
        child: Text('递增')
      ),
    );
  }
}

